package com.thatvn.diemtinvietnam;

import com.thatvn.diemtinvietnam.R;
import com.thatvn.diemtinvietnam.SpinnerNavItem;
 





import java.util.ArrayList;
 





import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.content.res.AssetManager;
import android.graphics.Typeface;
public class TitleNavigationAdapter extends BaseAdapter {
 
    private ImageView imgIcon;
    private TextView txtTitle;
    private ArrayList<SpinnerNavItem> spinnerNavItem;
    private Context context;
    public Typeface typefaceTitle;
    public ImageLoader imageLoader;
    public String image;
    public TitleNavigationAdapter(Context context,
            ArrayList<SpinnerNavItem> spinnerNavItem) {
    	//Log.e("TitleNavigationAdapter", "1");
        this.spinnerNavItem = spinnerNavItem;
        //Log.e("TitleNavigationAdapter", "2");
        this.context = context;
        imageLoader=new ImageLoader(context);
        //Log.e("TitleNavigationAdapter", "3");
        typefaceTitle=Typeface.createFromAsset(context.getAssets(),"fonts/Roboto-Black.ttf");
        //typefaceTitle=Typeface.createFromAsset(context.getAssets(),"fonts/Roboto-Black.ttf");
        //Log.e("TitleNavigationAdapter", "4");
    }
 
    @Override
    public int getCount() {
        return spinnerNavItem.size();
    }
 
    @Override
    public Object getItem(int index) {
        return spinnerNavItem.get(index);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) { 
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater)
                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
        }
         
        imgIcon = (ImageView) convertView.findViewById(R.id.imgIcon);
        txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
        //Log.e("getView", "1");
        txtTitle.setTypeface(typefaceTitle);  
        //Log.e("getView", "2");        
        txtTitle.setText(spinnerNavItem.get(position).getTitle());
        if (Config.typeView==0){
	        imgIcon.setImageResource(spinnerNavItem.get(position).getIcon());
	        imgIcon.setVisibility(View.GONE);
        }else{
        	if (position==0){
        		image=Utils.getDomainImageMobile(Config.currentDomainName);
        		imageLoader.DisplayImage(image, imgIcon);
        	}else{
        		imgIcon.setImageResource(spinnerNavItem.get(position).getIcon());
    	        imgIcon.setVisibility(View.GONE);
        	}
        }
        return convertView;
    }
     
 
    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater)
                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
        }         
        imgIcon = (ImageView) convertView.findViewById(R.id.imgIcon);
        txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);   
       // if (Config.typeView==0){
	        imgIcon.setImageResource(spinnerNavItem.get(position).getIcon()); 
	        imgIcon.setVisibility(View.GONE);
        //}else{
//        	if (position==0){
//        		image=Utils.getDomainImageMobile(Config.currentDomainName);
//        		imageLoader.DisplayImage(image, imgIcon);
//        	}else{
//        		imgIcon.setVisibility(View.GONE);
//        	}
//        }
        txtTitle.setText(spinnerNavItem.get(position).getTitle());
        return convertView;
    }
 
}
